﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain;
using Ue.Qcdz.Domain.Membership;
using Ue.Qcdz.Domain.SaleInfos;
using Ue.Qcdz.Domain.Shops;

namespace Ue.Qcdz.UI.Controls.SaleInfo
{
    public class UserSalinfoManger : SkinnedGridView
    {
        private string skinFileName = "~/Themes/zh-cn/Skins/SaleInfo/UserMangerSalInfo.ascx";
        private SaleInfoTypeDropDown saleInfoTypeDropDown;
        
        #region Overrides of SkinnedControl
        protected override string GetSkinFileName()
        {
            return skinFileName;
        }
        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            saleInfoTypeDropDown = skin.FindControl<SaleInfoTypeDropDown>("saleInfoTypeDropDown");
            base.InitializeSkin(skin);
        }
        #endregion

        #region Overrides of SkinnedGridView

        protected override void GridViewDataBind(object sender, EventArgs args)
        {


            if (SiteContext.GetSiteContext().User != null)
            {
                if (SiteContext.GetSiteContext().User != null)
                {
                    User user = SiteContext.GetSiteContext().User;
                    string userId = user.Key.ToString();
                    IShopRepository shopRepository =
                        Ue.Infrastructure.RepositoryFramework.RepositoryFactory.GetRepository
                            <IShopRepository, Ue.Qcdz.Domain.Shops.Shop>();
                    Shop shop = shopRepository.GetShop(user);
                    ISaleInfoRepository repository =
                        Ue.Infrastructure.RepositoryFramework.RepositoryFactory.GetRepository
                            <ISaleInfoRepository, Ue.Qcdz.Domain.SaleInfos.SaleInfo>();
                    IList<Ue.Qcdz.Domain.SaleInfos.SaleInfo> list = repository.FindBy(userId, shop.Key.ToString());
                    Repeater repeater = sender as Repeater;
                    repeater.DataSource = list;
                    repeater.DataBind();
                    this.RecordCount = list.Count;
                }
            }
            else
            {
                MessageWindow.RenderMessage("请您登陆", "Login.aspx");
            }

        }
        #endregion
    }
}
